<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty indent modifier plugin
 *
 * Type:     modifier<br>
 * Name:     indent<br>
 * Purpose:  indent lines of text
 * @link http://smarty.php.net/manual/en/language.modifier.indent.php
 *          indent (Smarty online manual)
 * @param string
 * @param integer
 * @param string
 * @return string
 */
function smarty_function_form_line($params, &$smarty)
{
    $p = array_merge(array(
      'name'      =>  ''
     ,'type'      =>  'text'
     ,'textarea'  => array('cols'=>50,'rows'=>3)
     ,'id'        =>  ''
     ,'li_class'  =>  ''
     ,'class'     =>  ''
     ,'style'     =>  ''
     ,'more'      =>  ''
     ,'label'     =>  ''
     ,'value'     =>  ''
     ),$params);

    if(empty($p['id'])) $p['id'] = str_replace (array('[',']'), array('-',''), $p['name']);
    
    $args=$li_args='';
    
    foreach (array('type','id','name','class','style') as $arg){
      if(!empty($p[$arg])){
        $args .= ($args=='' ? '' : ' ').$arg.'="'.$p[$arg].'"';
      }

      if(!empty($p["li_$arg"])){
        $li_args .= ($li_args=='' ? '' : ' ').$arg.'="'.$p["li_$arg"].'"';
      }

    }


    $html ='<li '. $li_args .'><label for="'.$p['id'].'">'.$p['label'].'</label>';
    if($p['type']=='textarea'){
      $open = sprintf('<textarea cols="%d" rows="%d" $args$>$value$',$p['textarea']['cols'],$p['textarea']['rows']);
      $test = $p['value'];
      $close = '</textarea>';
    } else {
      $open ='<input $args$ value="$value$" ';
      $close =' />';
    }
    
    switch($p['type']){
      case 'checkbox':
        if($p['value']==1 || $p['value']=='checked'){
          $args .= ' checked="checked"' ;
          $open = str_replace('value="$value$"', '', $open);
        }
      default:
        
        break;
    }

    foreach (array('type','id','name','class','style') as $arg){
      if(!empty($p[$arg])){
        $args .= ($args=='' ? '' : ' ').$arg.'="'.$p[$arg].'"';
      }
    }

    if(!empty($p['more'])){
      $args.=" ".$p['more'];
    }

    $open = str_replace(array('$args$','$value$'), array($args,$p['value']), $open);

    $html.=$open.$close.'</li>';
        
    return $html;
}

?>
